package com.fr.report.web;

import com.fr.base.ArrayUtils;
import com.fr.base.XMLable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.web.event.Listener;
import java.util.ArrayList;
import java.util.List;

public abstract class WebContent
  implements XMLable
{
  public static final String EVENT_BEFORE_TO_PDF = "beforetopdf";
  public static final String EVENT_AFTER_TO_PDF = "aftertopdf";
  public static final String EVENT_BEFORE_TO_EXCEL = "beforetoexcel";
  public static final String EVENT_AFTER_TO_EXCEL = "aftertoexcel";
  public static final String EVETN_BEFORE_TO_WORD = "beforetoword";
  public static final String EVENT_AFTER_TO_WORD = "aftertoword";
  public static final String EVENT_BEFORE_PDF_PRINT = "beforepdfprint";
  public static final String EVENT_AFTER_PDF_PRINT = "afterpdfprint";
  public static final String EVENT_BEFORE_FLASH_PRINT = "beforeflashprint";
  public static final String EVENT_AFTER_FLASH_PRINT = "afterflashprint";
  public static final String EVENT_BEFORE_APPLET_PRINT = "beforeappletprint";
  public static final String EVENT_AFTER_APPLET_PRINT = "afterappletprint";
  public static final String EVENT_BEFORE_EMAIL = "beforeemail";
  public static final String EVENT_AFTER_EMAIL = "afteremail";
  protected List listenerList;
  protected ToolBarManager[] managers;

  public String[] supportedEvents()
  {
    return new String[] { "startload", "afterload", "beforetopdf", "aftertopdf", "beforetoexcel", "aftertoexcel", "beforetoword", "aftertoword", "beforepdfprint", "afterpdfprint", "beforeflashprint", "afterflashprint", "beforeappletprint", "afterappletprint" };
  }

  public int getListenerSize()
  {
    return ((this.listenerList == null) ? 0 : this.listenerList.size());
  }

  public Listener getListener(int paramInt)
  {
    return ((this.listenerList == null) ? null : (Listener)this.listenerList.get(paramInt));
  }

  public void addListener(Listener paramListener)
  {
    if (paramListener == null)
      return;
    String[] arrayOfString = supportedEvents();
    if (ArrayUtils.isEmpty(arrayOfString))
      return;
    for (int i = 0; i < arrayOfString.length; ++i)
      if (arrayOfString[i].equals(paramListener.getName()))
      {
        if (this.listenerList == null)
          this.listenerList = new ArrayList();
        this.listenerList.add(paramListener);
        return;
      }
  }

  public void clearListeners()
  {
    if (this.listenerList != null)
      this.listenerList.clear();
  }

  public ToolBarManager[] getToolBarManagers()
  {
    return this.managers;
  }

  public void setToolBarManagers(ToolBarManager[] paramArrayOfToolBarManager)
  {
    this.managers = paramArrayOfToolBarManager;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      this.managers = null;
      clearListeners();
    }
    if (paramXMLableReader.isChildNode())
    {
      Object localObject;
      String str = paramXMLableReader.getTagName();
      if (str.equals("Listener"))
      {
        localObject = new Listener();
        paramXMLableReader.readXMLObject((XMLReadable)localObject);
        addListener((Listener)localObject);
      }
      else if (str.equals("ToolBars"))
      {
        localObject = new ArrayList();
        paramXMLableReader.readXMLObject(new XMLReadable(this, (List)localObject)
        {
          private final List val$managerList;
          private final WebContent this$0;

          public void readXML()
          {
            if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("ToolBarManager")))
            {
              ToolBarManager localToolBarManager = new ToolBarManager();
              paramXMLableReader.readXMLObject(localToolBarManager);
              this.val$managerList.add(localToolBarManager);
            }
          }
        });
        this.managers = ((ToolBarManager[])((List)localObject).toArray(new ToolBarManager[((List)localObject).size()]));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    int i = 0;
    int j = getListenerSize();
    while (i < j)
    {
      Listener localListener = getListener(i);
      localListener.writeXML(paramXMLPrintWriter);
      ++i;
    }
    if (this.managers != null)
    {
      paramXMLPrintWriter.startTAG("ToolBars");
      i = 0;
      j = (this.managers == null) ? 0 : this.managers.length;
      while (i < j)
      {
        this.managers[i].writeXML(paramXMLPrintWriter);
        ++i;
      }
      paramXMLPrintWriter.end();
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    int i;
    WebContent localWebContent = (WebContent)super.clone();
    if (this.listenerList != null)
    {
      localWebContent.listenerList = new ArrayList();
      i = 0;
      int j = getListenerSize();
      while (i < j)
      {
        localWebContent.listenerList.add(getListener(i).clone());
        ++i;
      }
    }
    if (this.managers != null)
    {
      localWebContent.managers = new ToolBarManager[this.managers.length];
      for (i = 0; i < this.managers.length; ++i)
        localWebContent.managers[i] = ((ToolBarManager)this.managers[i].clone());
    }
    return localWebContent;
  }
}